package com.srpingde.hhh;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.SimpleImageLoadingListener;
import com.springde.hhh.R;
import com.srpingde.hhh.application.HhhApp;
import com.srpingde.hhh.application.HHHDataManage;
import com.srpingde.hhh.bean.DingDanBean;
import com.srpingde.hhh.bean.DingDanBeanData;
import com.srpingde.hhh.jiekou.HHHIml;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.RelativeLayout.LayoutParams;

public class DingDanDetailActivity extends Activity {
	DingDanBean guangGao;
	ImageView back;
	TextView dingdan_detail_address,dingdan_detail_name,dingdan_detail_diangdanhao,dingdan_detail_time;
	LinearLayout dingdan_detail_ly;
	//TextView dingdan_detail_yunfei,dingdan_detail_allprice;
	TextView dingdan_detail_allprice;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ding_dan_detail);
        back = (ImageView) findViewById(R.id.about_back);
        guangGao = HHHDataManage.getInstance().getDingDanBean();
        dingdan_detail_address = (TextView) findViewById(R.id.dingdan_detail_address);
        dingdan_detail_name = (TextView) findViewById(R.id.dingdan_detail_name);
        dingdan_detail_diangdanhao = (TextView) findViewById(R.id.dingdan_detail_diangdanhao);
        dingdan_detail_time = (TextView) findViewById(R.id.dingdan_detail_time);
        dingdan_detail_ly = (LinearLayout) findViewById(R.id.dingdan_detail_ly);
        //dingdan_detail_yunfei = (TextView) findViewById(R.id.dingdan_detail_yunfei);
        dingdan_detail_allprice = (TextView) findViewById(R.id.dingdan_detail_allprice);
        if(getIntent().getExtras()!=null){
        	String str;
        	DingDanBeanData dingDanBean = guangGao.getRows().get(getIntent().getIntExtra("id", 0));
        	dingdan_detail_address.setText("地址: "+dingDanBean.getAddress());
        	dingdan_detail_name.setText("姓名: "+dingDanBean.getName());
        	
        	dingdan_detail_diangdanhao.setText("订单编号: "+dingDanBean.getOrderno());
        	str = dingDanBean.getOrderno();
        	dingdan_detail_time.setText("创建时间: "+ str.subSequence(0, 4) + "-" + str.subSequence(4, 6) + "-" + str.subSequence(6, 8) + "/" + str.subSequence(8, 10) + ":" + str.subSequence(10, 12));
        	for(DingDanDetailBean bean : dingDanBean.getDetail()){
        		View view = LayoutInflater.from(this).inflate(R.layout.dingdan_detail_item, null);
        		ImageView dingdan_detail_iv = (ImageView) view.findViewById(R.id.dingdan_detail_iv);
        		TextView dingdan_detail_style = (TextView) view.findViewById(R.id.dingdan_detail_style);
        		TextView dingdan_detail_show_num = (TextView) view.findViewById(R.id.dingdan_detail_show_num);
        		TextView dingdan_detail_jine = (TextView) view.findViewById(R.id.dingdan_detail_jine);
        		dingdan_detail_style.setText("款式: "+bean.getStyle());
        		dingdan_detail_show_num.setText("数量: "+bean.getAmount());
        		dingdan_detail_jine.setText("小计: "+bean.getPrice());
        		final ImageView kvShow = dingdan_detail_iv;
        		ImageLoader.getInstance().loadImage(HHHIml.httpHeader+bean.getPurl(), new SimpleImageLoadingListener(){
        			@Override
        			public void onLoadingComplete(String imageUri, View view, Bitmap bitmap) {
        				BitmapDrawable bitmapDrawable = new BitmapDrawable(bitmap);
        				//kvShow.setImageBitmap(bitmap);
        				kvShow.setBackgroundDrawable(bitmapDrawable);
        			}
        		});
        		dingdan_detail_ly.addView(view);
        	}
        	/*dingdan_detail_yunfei.setText("运费: "+dingDanBean.getYunfei());*/
        	dingdan_detail_allprice.setText("应付金额: "+dingDanBean.getMoney());
        }
        layout();
    }
  //点击事件
  	public void onClick(View v){
  		switch (v.getId()) {
  		case R.id.about_back:
  			finish();
  			break;
  		}
  	}
  	 private void layout() {
 		// 头的高度
 		TextView top_title_tv = (TextView) findViewById(R.id.about_title);
 		RelativeLayout.LayoutParams titleLayoutParams = (RelativeLayout.LayoutParams) top_title_tv.getLayoutParams();
 		titleLayoutParams.height = HhhApp.getInstance().title_h();
 		top_title_tv.setLayoutParams(titleLayoutParams);
 		//返回按钮
 		RelativeLayout.LayoutParams backLayoutParams = (LayoutParams) back.getLayoutParams();
 		backLayoutParams.height = HhhApp.getInstance().title_h();
 		back.setLayoutParams(backLayoutParams);
 	}
}
